package com.ldr.custom.spring.v3.aop.intercept;

import com.ldr.custom.spring.v3.aop.GPJoinPoint;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

public class GPAfterReturningAdviceInterceptor extends GPAbstractAspectAdvice implements GPMethodInterceptor {

    private GPJoinPoint joinPoint;

    public GPAfterReturningAdviceInterceptor(Method aspectMethod, Object aspectTarget) {
        super(aspectMethod, aspectTarget);
    }

    private void afterReturning(Object returnValue, Method method, Object[] arguments, Object aThis) throws InvocationTargetException, IllegalAccessException {
        super.invokeAdviceMethod(joinPoint,returnValue,null);
    }

    @Override
    public Object invoke(GPReflectiveMethodInvocation mi) throws Throwable {

        Object returnValue = mi.proceed();
        this.joinPoint=mi;
        this.afterReturning(returnValue,mi.getMethod(),mi.getArguments(),mi.getThis());
        return returnValue;
    }
}
